package com.gscitysfy.cus.drain.modules.command.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.gscitysfy.cloudfrmwk.assistant.domain.Result;
import com.gscitysfy.cus.drain.annotations.DictTranslation;
import com.gscitysfy.cus.drain.annotations.FieldParam;
import com.gscitysfy.cus.drain.constants.DicConstant;
import com.gscitysfy.cus.drain.modules.command.dto.IPageDto;
import com.gscitysfy.cus.drain.modules.command.dto.ReservePlanManageDto;
import com.gscitysfy.cus.drain.modules.command.service.IReservePlanManageService;
import com.gscitysfy.cus.drain.modules.command.vo.ReservePlanManageQuery;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author Administrator
 * @since 2022-10-22 11:21:35
 */
@Tag(name = "辅助决策 -> 预案管理MIS")
@AllArgsConstructor
@RestController
@RequestMapping(value = "/reserve")
public class ReservePlanManageController {

    private final IReservePlanManageService iReservePlanManageService;

    @Operation(summary = "获取预案管理列表")
    @DictTranslation({
            @FieldParam(dictType = DicConstant.RESERVE_PLAN_GRADE, targetField = "grade"),
            @FieldParam(dictType = DicConstant.COMMAND_DANGER_TYPE, targetField = "type")
    })
    @GetMapping("/list")
    public Result<IPage<ReservePlanManageDto>> pageList(IPageDto page, ReservePlanManageQuery query) {
        return Result.content(iReservePlanManageService.fetchPage(page.getPage(), query));
    }

    @Operation(summary = "获取预案管理详情")
    @DictTranslation({
            @FieldParam(dictType = DicConstant.RESERVE_PLAN_GRADE, targetField = "grade"),
            @FieldParam(dictType = DicConstant.COMMAND_DANGER_TYPE, targetField = "type")
    })
    @GetMapping("/{cmKid}")
    public Result<ReservePlanManageDto> fetchById(@PathVariable Long cmKid) {
        return Result.content(iReservePlanManageService.fetchById(cmKid));
    }

    @Operation(summary = "新增预案管理")
    @PostMapping
    public Result<Boolean> save(@RequestBody ReservePlanManageDto dto) {
        return Result.content(iReservePlanManageService.saveOrUpdate(dto));
    }

    @Operation(summary = "修改预案管理")
    @PutMapping
    public Result<Boolean> update(@RequestBody ReservePlanManageDto dto) {
        return Result.content(iReservePlanManageService.saveOrUpdate(dto));
    }

    @Operation(summary = "删除预案管理")
    @PutMapping(value = "/delete")
    public Result<Boolean> delete(@RequestBody List<Long> idList) {
        return Result.content(iReservePlanManageService.delete(idList));
    }


    @Operation(summary = "是否启用预案管理")
    @PutMapping(value = "/enable/{cmKid}")
    public Result<Boolean> enable(@PathVariable Long cmKid) {
        return Result.content(iReservePlanManageService.enable(cmKid));
    }

}
